/*
 * @Author: Deven
 * @Email: liming@tuya.com
 * @LastEditors: Please set LastEditors
 * @FileName: &file name&
 * @Description: 
 * @Copyright: HANGZHOU TUYA INFORMATION TECHNOLOGY CO.,LTD
 * @Company: http://www.tuya.com
 * @Date: 2020-11-07 17:16:29
 * @LastEditTime: 2020-12-30 10:38:18
 */

#ifndef _RADIO_CARD_H__
#define _RADIO_CARD_H__

#include "tal_system.h"
#include "rf_mf_stack_cfg.h"
#include "pbuf.h"

#ifdef __cplusplus
extern "C" {
#endif

struct rf_card;

/* receive type */
typedef enum {
    UNICAST = 0,
    BROADCAST,
}RECV_MTD_T;

typedef INT8_T (*input_fn)(struct pbuf *p, struct rf_card *card);
typedef INT8_T (*rf_output_fn)(struct rf_card *card, struct pbuf *p);
typedef INT8_T (*rf_card_init_fn)(struct rf_card *card, input_fn input);
typedef INT8_T (*recv_cb_fn)(UINT8_T* src_mac, RECV_MTD_T type, UINT8_T *p_data, UINT16_T len);

struct rf_card {
    struct rf_card *next;
    /* mac layer input function */
    input_fn input;
    /* radio phy layer output function */
    rf_output_fn rf_output;
    /* app layer recvieve callback function */
    recv_cb_fn recv_cb;
    /* rf transmitting power */
    UINT8_T rf_power;
    /* rf transmitting channel */
    UINT8_T channel;
    /* number of bytes used in hwaddr */
    UINT8_T hwaddr_len;
    /* link level hardware address of this interface */
    UINT8_T hwaddr[MAX_HWADDR_LEN];
    /* Maximum segment size(hdr + payload) */
    UINT8_T mtu;
    /* number of this interface. */
    UINT8_T num;
    /* descriptive abbreviation */
    char name[2];
};


#define get_card_index(card)      ((UINT8_T)((card)->num + 1))

INT8_T rf_card_add_and_init(struct rf_card *card, recv_cb_fn recv_cb, rf_card_init_fn init);
struct rf_card* rf_card_get_default(void);
INT8_T rf_card_set_default(struct rf_card *p_card);
struct rf_card* rf_card_get_from_num(UINT8_T num);
struct rf_card* rf_card_get_from_addr(UINT8_T* dest);


#ifdef __cplusplus
}
#endif

#endif  // end _RADIO_CARD_H__
